package com.lie.prepare.sort;

import org.junit.Test;

import static com.lie.prepare.sort.util.MyArrayHelper.getArray;
import static com.lie.prepare.sort.util.MyArrayHelper.printArraySort;

/**
 * Created by lie on 2018/4/18.
 */
public class InsertSort {

    public static void doSort(){
        int[] array = getArray();

        int temp;
        int indexTemp;
        for (int i = 0; i < array.length -1 ; i++) {
            temp = array[i+1];
            indexTemp = i;
            while (indexTemp>=0 && temp< array[indexTemp]){
                array[indexTemp+1] = array[indexTemp];
                indexTemp--;
            }
            array[indexTemp+1] = temp;

        }
        printArraySort(array);
    }

    @Test
    public void test(){
        doSort();
    }


}
